class ModificationController < ApplicationController
  def restaurant
    @restaurant = Restaurant.all
  end
  def user
    @user = Uesr.all
    p '==========================='
    p @user
  end
  def dishes
    @dishes = Dish.where({rest_name:params[:rest_name]})
    p '==================='
    p params[:rest_name]
    p @dishes
  end
  def destroy

    @restaurant = Restaurant.find(params[:id])
    @restaurant.destroy
    redirect_to '/modification/restaurant'
  end
  def destroy_dis
    @dishes = Dish.find(params[:id])
    @dishes.destroy
    redirect_to :back
  end
  def destroy_user
    @user = Uesr.find(params[:id])
    @user.destroy
    redirect_to '/modification/user'
  end
  def edit_dis
    @dishes = Dish.find(params[:id])
    @dishes.destroy
    redirect_to '/modification/editDishes'
  end
  def edit_user
    @user = Uesr.find(params[:id])
    @user.destroy
    redirect_to '/modification/editUser'
  end
  def edit
    @restaurant = Restaurant.find(params[:id])
    @restaurant.destroy
    redirect_to '/modification/editRes'
  end
  def getSelectedText
    p params
    @restaurant = Restaurant.new({rest_name: params[:res_name]})
    @restaurant.save
    render :json => {status: true}
  end
  def getText
    @user = Uesr.new({user_name: params[:user_name]})
    p '===================='
    p @user
    @user.save
    render :json => {status: true}
  end
  def getDisText
    @dishes = Dish.new({dishes_name: params[:dis_name],rest_name: params[:rest_name],price:params[:price],dis_id:params[:dis_id]})
    @dishes.save
    render :json => {status: true}
  end
  def saveReName
    @saveRest = Restaurant.new({save_name: params[:input_R1]})
    @saveRest.save
    p '==========================='
    p @saveRest
  end
  def showUser
    @showUser = Uesr.find_by_user_name(params[:user_name])
    if @showUser ==nil
      redirect_to '/modification/user'
    end
  else
  end
  def showDis
    @showDis = Dish.find_by_dishes_name(params[:dishes_name])
    if @showDis ==nil
      redirect_to :back
    end
  end
  def showRes
    @showName = Restaurant.find_by_rest_name(params[:rest_name])
    if @showName ==nil
      redirect_to '/modification/restaurant'
    end
  end
  def update
    @dishes = Dish.find(params[:id])
    if @dishes.update({dishes_name: params[:dis_name],price:params[:price]})
      p params[:dis_name]
      p params[:price]
    else
      render 'dishes'
    end
  end
  def updateRes
    @restaurant = Restaurant.find(params[:id])
    if @restaurant.update({rest_name: params[:res_name]})
    else
      render 'restaurant'
    end
  end
  def updateUser
    @user = Uesr.find(params[:id])
    if @user.update({user_name:params[:user_name]})
    else
      render 'user'
    end
  end
  def modifyUser
    @user = Uesr.find(params[:id])
  end
  def modifyRes
    @restaurant = Restaurant.find(params[:id])
  end
  def modifyDish
    @dishes = Dish.find(params[:id])
  end
end